package com.ymt.bpm.web.rest.platform.statistics;

import com.ymt.bpm.service.platform.statistics.StatisticsService;
import com.ymt.bpm.util.Const;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by Johnny on 2017/6/27.
 */
@RequestMapping("/api/v1/platform/statistics")
@RestController
public class StatisticsResource {

    /**
     * Logger
     */
    private Logger log = LoggerFactory.getLogger(this.getClass());

    /**
     * StatisticsService
     */
    @Autowired
    private StatisticsService ss;

    @GetMapping("/dashboard/totalCount")
    public String dhTotalCount() {
        return null;
    }

    @PostMapping("/bpdkpi")
    public String bpdkpi(HttpServletRequest req,
                         @RequestParam("param") String param) {
        Map<String, String> userDetail = (Map<String, String>) SecurityContextHolder.getContext().getAuthentication().getDetails();
        String tenantId = userDetail.get(Const.TENANT_ID);
        if (log.isDebugEnabled()) {
            log.debug("bpdkpi tenantId="+tenantId);
            log.debug("bpdkpi param="+param);
        }
        String rtn = ss.bpdkpi(tenantId, param);
        if (log.isDebugEnabled()) {
            log.debug("bpdkpi rtn="+rtn);
        }
        return rtn;
    }

}
